package com.user.service.impl;

import com.user.mapper.EmpMapper;
import com.user.pojo.Emp;
import com.user.service.EmpService;
import com.user.utils.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageResult<Emp> findPage(Map<String,Object> searchMap, int page, int size) {
        PageHelper.startPage(page,size);
        List<Emp> empList = empMapper.findByPage(searchMap);
        PageInfo<Emp> pageInfo = new PageInfo<>(empList);
        return new PageResult<Emp>(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public Emp findById(Integer id) {
        return empMapper.selectById(id);
    }

    @Override
    public int save(Emp emp) {
        return empMapper.insert(emp);
    }

    @Override
    public int updateById(Emp emp) {
        return empMapper.updateById(emp);
    }

    @Override
    public int deleteById(Integer id) {
       return empMapper.deleteById(id);
    }
}
